<?php
/**
 * Object Relational Persistence Mapping Class for table: rad_additional_service_item
 *
 * @package	com.athena
 * @author	LHV
 */
class RadAdditionalServiceItem extends ORDataObject {

	/**#@+
	 * Fields of table: rad_additional_service_item mapped to class members
	 */
	var $rad_additional_service_item_id	= '';
	var $rad_ticket_item_id        		= '';
	var $rad_additional_service_id		= '';
	var $price                     		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'rad_additional_service_item';

	/**
	 * Primary Key
	 */
	var $_key = 'rad_additional_service_item_id';

	/**
	 * Internal Name
	 */
	var $_internalName = 'RadAdditionalServiceItem';

	/**
	 * Handle instantiation
	 */
	function RadAdditionalServiceItem() {
		parent::ORDataObject();
	}

    public function deleteByTicketItem($radTicketItemId) {
        $sql    =   "DELETE FROM $this->_table WHERE rad_ticket_item_id='$radTicketItemId'";
        $this->_execute($sql);
    }

    public function setData($radTicketItemId, $serviceId, $price) {
    	$data  =   array(
    	   'rad_ticket_item_id'        =>  $radTicketItemId,
    	   'rad_additional_service_id' =>  $serviceId,
    	   'price'                     =>  $price
    	);
    	$this->populateArray($data);
    }

    public function getServicesByTicketItem($radTicketItemId = 0) {
        $ds =& new Datasource_sql();
        $sql = array(
            'cols'  => "rad_additional_service_id",
            'from'  => "$this->_table",
            'where' => "rad_ticket_item_id='$radTicketItemId'"
            );
        $ds->setup($this->_db, $sql);

        return $ds->toArray('rad_additional_service_id');
    }

    public function getPriceInfoByTicketItem($radTicketItemId) {
        $sql   =   "SELECT SUM(price) price FROM $this->_table WHERE rad_ticket_item_id='$radTicketItemId'";
    	$res   =   $this->_execute($sql);
    	if ($res && !$res->EOF) {
    		return $res->fields['price'];
    	}
        return 0;
    }
}
?>
